﻿using System.Linq;
using System.Web.Mvc;
using IFDB.ViewModels.PartialViewModels;

namespace IFDB.MVC.Controllers
{
    public class MenuController : Controller
    {
        public ActionResult GetTeams(string term)
        {
            SearchViewModel searchViewModel = new SearchViewModel();
            var teams = searchViewModel.SearchTeams(term)
                .Select(t => new
                {
                    label = t.Name,
                    value = t.TeamId
                }).ToList();

            return Json(teams, JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetPersons(string term)
        {
            SearchViewModel searchViewModel = new SearchViewModel();
            var teams = searchViewModel.SearchPersons(term)
                .Select(p => new
                {
                    label = string.Format("{0} {1}", p.Forenames, p.Surname).Trim(),
                    value = p.PersonId
                }).ToList();

            return Json(teams, JsonRequestBehavior.AllowGet);
        }
    }
}
